﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SnmpForm.APConfig
{
    public partial class FrmLedLight : frmApConfig
    {
        public FrmLedLight(BusinessWrapper.Ap ap)
            :base(ap)
        {
            InitializeComponent();
        }

        private void FrmLedLight_Load(object sender, EventArgs e)
        {
            Update();
        }

        public override bool Update(bool bView = true)
        {
            DbWrapper.DbDataTypes.Advance_tools info =
                m_ap.GetAdvanceTools();
            if (bView)
            {
                ucLedLight1.initWith(info);
            }
            else
            {
                info.led_light = ucLedLight1.Get().led_light;
            }
            return true;
        }

        public override bool SaveToDb()
        {
            Update(false);
            bool bSuccess =
                BusinessWrapper.User.Instance.ModifyAdvanceTools(m_ap);
            if (bSuccess)
            {
                MessageBox.Show("保存成功");
                Close();
            }
            else
            {
                MessageBox.Show("保存失败");
            }
            return bSuccess;
        }

        public override bool SyncToApCommit()
        {
            DbWrapper.DbDataTypes.Advance_tools info =
                m_ap.GetAdvanceTools();
            return m_ap.SetLedLight(info.led_light);
        }

        private void buttonSave_Click(object sender, EventArgs e)
        {
            if (Update(false))
            {
                if (SyncToAp())
                {
                    if (SaveToDb())
                    {
                        Close();
                    }
                }
            }
        }
    }
}
